#include "beep.h"
 
#include "systick.h"

#ifdef SEGLCD   
    #include "SegLCD.h"
#elif defined DIGLED
    #include "TM1638.h"
#endif

TBeep Beep;

 
void BeepOnce()
{
    BEEP_ON;
    delay_ms(80);
    BEEP_OFF;
}

 
void BeepTime(uint16_t ms)
{
    BEEP_ON;
    delay_ms(ms);
    BEEP_OFF;
}

 
void BeepTwinkle()
{
#ifdef SEGLCD   
    LCDLED_TOG;
#elif defined DIGLED
    TM1638_Switch(0);
#endif
    BeepOnce();
#ifdef SEGLCD   
    LCDLED_TOG;
#elif defined DIGLED
    TM1638_Switch(1);
#endif
}

 
void BeepGap(uint8_t ATimes)
{
    while (ATimes > 0) 
    {
        ATimes = ATimes - 1;
        BeepOnce();
        delay_ms(80);
    }
}

 
void InitBeep() 
{
    rcu_periph_clock_enable(BEEP_GPIO_CLK);

    gpio_mode_set(BEEP_GPIO_PORT, GPIO_MODE_OUTPUT, GPIO_PUPD_PULLUP, BEEP_GPIO_PIN);
    gpio_output_options_set(BEEP_GPIO_PORT, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, BEEP_GPIO_PIN);
    BEEP_OFF;

    Beep.BeepGap = BeepGap;
    Beep.BeepOnce = BeepOnce; 
    Beep.BeepTime = BeepTime;
    Beep.BeepTwinkle = BeepTwinkle;

}